package com.ase.leetcode.数组中重复的数字;

import java.util.*;

/**
 * @author gyhstart
 * @create 2021/3/18 - 17:39
 **/
public class Solution {
    public static int findRepeatNumber(int[] nums) {
        int temp;
        for (int i = 0; i < nums.length; i++) {
            while (i != nums[i]) {
                if (nums[i] == nums[nums[i]]) {
                    return nums[i];
                }
                temp = nums[nums[i]];
                nums[nums[i]] = nums[i];
                nums[i] = temp;
            }
        }
        return -1;

    }

    public static void main(String[] args) {
        int[] arr = {2, 3, 1, 0, 2, 5, 3};
        System.out.println("findRepeatNumber(arr) = " + findRepeatNumber(arr));
    }
}
